package wiki.generic.concretecontents;

import java.util.List;

import wiki.generic.contents.Content;
import wiki.generic.med.GeneralPurposeService;
import wiki.generic.med.ViewingService;
/**
 * 
 * @author <p><strong>JwTeam</strong></p> 
 *
 */
public class DownloadableFile extends ConcreteContent{

	private static final int MAX_NAME_LENGTH=30;
	private ViewingService ps;
	private GeneralPurposeService gps;
	
	public DownloadableFile(String nome, String type, int ID,
			List<String> attributes, ViewingService ps, GeneralPurposeService gps) {
		super(nome, type, ID, attributes);
		this.ps=ps;
		this.gps=gps;
	}

	@Override
	public String getHTMLCode() {
		String code="<div class='down'\n>";
		code+="<img src='./html/immagini/downimg.png'/>\n" +
				"<div class='down-box'>\n" +
				"<h3>Scarica il file:</h3>\n" +
				"<table>\n" +
				"<tr>\n" +
				"<td class='coldown1'>\n"; 
		String p=ps.getContentMainParameterbyID(type, ID).getInfo();
		String s=gps.getFileName(p);		
		String sub=s;
		String ext=new String();
		if(s.length()>(MAX_NAME_LENGTH+2)){
			sub=s.substring(0, MAX_NAME_LENGTH)+"...";
			ext=gps.getExtension(s);
		}
		code+="<p>"+sub+ext+"</p>\n" +
						"</td>\n" +
						"<td>\n" +
						"<a href='"+ps.getContentMainParameterbyID(type, ID).getInfo()+"'>\n" +
								"<div class='downloadbutton'></div></a>\n" +
								"</td>\n" +
								"</tr>\n" +
								"</table></div></div>\n";
		return code; 	
	}

	@Override
	public Content clone() {
		return new DownloadableFile(nome, type, ID, attributes, ps,gps);
	}

	
	
}
